package com.gxa.retail_admin.controller;


import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.pojo.Employee;
import com.gxa.modules.service.EmployeeService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 工作台员工系统
 */
@Controller
@Api(value = "测试数据",tags = "工作台员工接口—陈峰江")
@RequestMapping("/staging/system")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 分页查询员工接口
     * @param page
     * @param limit
     *
     */
    @GetMapping("/queryEmployee")
    @ApiOperation(value = "员工查询接口",notes = "分页查询所有员工信息",httpMethod = "GET",response = JsonResult.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 405,message = "方法不允许"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "limit",value = "每页显示条数",paramType = "query",dataType = "String")
    })
    @ResponseBody
    @RequiresPermissions("员工管理")
    public JsonResult queryEmployee(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {

        return employeeService.queryEmployee(page, limit);
    }


    /**
     * 添加员工接口
     * @param employee
     *
     */
@PostMapping("/addEmployee")
@ApiOperation(value = "添加员工接口",notes = "传递实体添加员工",httpMethod = "POST",response = ResultVo.class)
@ApiResponses({
        @ApiResponse(code = 200,message = "查询成功"),
        @ApiResponse(code = 400,message = "参数接口问题"),
        @ApiResponse(code = 405,message = "方法不允许"),
        @ApiResponse(code = 500,message = "后端问题"),
})
@ResponseBody
@RequiresPermissions("员工管理")
   public ResultVo addEmployee(@RequestBody @ApiParam(name = "employee",value = "员工实体") Employee employee){


        return  employeeService.addEmployee(employee);
   }


    /**
     *删除员工
     * @param employee_numbers
     *
     */
    @PostMapping("/delEmployee")
    @ApiOperation(value = "批量删除/删除员工接口",notes = "传递员工id集合删除员工",httpMethod = "POST",response = ResultVo.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "查询成功"),
            @ApiResponse(code = 400,message = "参数接口问题"),
            @ApiResponse(code = 405,message = "方法不允许"),
            @ApiResponse(code = 500,message = "后端问题"),
    })
    @ApiImplicitParam(name = "employee_number",value = "员工id集合")
    @ResponseBody
    @RequiresPermissions("员工管理")
    public ResultVo delEmployee(@RequestBody List<Integer> employee_numbers){

        return  employeeService.delEmployee(employee_numbers);
    }

    /**
     * 员工搜索接口
     * @param page
     * @param pageSize
     * @param search
     * @return
     */
    @GetMapping(value = "/searchEmployee")
    @ApiOperation(value = "员工搜索",notes = "搜索接口",httpMethod = "GET", response = JsonResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数,默认为1",paramType = "query",required = false,dataType ="String" ),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数,默认为10",paramType = "query",required = false,dataType ="String" ),
            @ApiImplicitParam(name = "search",value = "搜索条件",paramType = "query",required = false,dataType ="String" )
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "success"),
            @ApiResponse(code=404,message = "找不到页面，接口或参数错误"),
            @ApiResponse(code = 405,message = "方法不允许"),
            @ApiResponse(code=500,message = "后台错误"),
    })
    @ResponseBody
    @RequiresPermissions("员工管理")
    public JsonResult searchEmployee(@RequestParam(defaultValue = "1")Integer page ,@RequestParam(defaultValue = "10")Integer pageSize,String search){


        return employeeService.searchEmployee(page,pageSize,search);
    }


}